package com.struts.action.product;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.spring.service.product.ProductMessageService;
import com.struts.form.MessageForm;
import com.struts.form.ProductMessageForm;

public class ProductMessageAction extends DispatchAction
{
	private ProductMessageService productMessageService=null;
	
	public ActionForward findProductMessage(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
	{
		int page=0;
		ProductMessageForm productmessageform=(ProductMessageForm)form;
		if(request.getParameter("page")!=null)
		{
			page=Integer.parseInt(request.getParameter("page"));
		}
		Map map=productMessageService.findProductMessage("from ProductMessage order by id desc",page);
		request.setAttribute("page_content", map.get("page_content"));
		request.setAttribute("productmessage_list", map.get("productmessage_list"));
		return mapping.findForward("ProductMessageList");
	}

	
	public ActionForward displayProductMessageInfo(ActionMapping mapping,ActionForm form,
			HttpServletRequest request,HttpServletResponse response)
	{
		Long id=0L;
		if(request.getParameter("id")!=null)
		{
			id=Long.parseLong(request.getParameter("id"));
		}
		Map map=productMessageService.displayProductMessageInfo(id);
		request.setAttribute("productmessage",map );
		return mapping.findForward("display_productmessage");
		
	}
	
	public ActionForward delProductMessage(ActionMapping mapping,ActionForm form,
			HttpServletRequest request,HttpServletResponse response)
	{
		if(request.getParameter("id")!=null)
		{
			boolean bool=productMessageService.delProductMessage(Long.parseLong(request.getParameter("id")));
			if(bool)
				return mapping.findForward("success");
		}
		return mapping.findForward("fail");
	}
	
	
	public ProductMessageService getProductMessageService() {
		return productMessageService;
	}

	public void setProductMessageService(ProductMessageService productMessageService) {
		this.productMessageService = productMessageService;
	}
	
}
